package com.studykun.client.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.studykun.client.model.teacher.EnglishToHiraganaTeacher;
import com.studykun.client.model.teacher.HiraganaToKanjiTeacher;
import com.studykun.client.model.teacher.KanjiToHiraganaTeacher;
import com.studykun.client.util.HasSyllabus;
import com.studykun.client.util.Room;
import com.studykun.client.util.SyllabusChangedHandler;

/**
 * The complete model.
 * @author John Ky <newhoggy@gmail.com>
 */
public class World implements HasSyllabus {
  final private ArrayList<SyllabusChangedHandler> syllabusChangedHandlers_ =
    new ArrayList<SyllabusChangedHandler>();
  final Syllabus syllabus_ = new Syllabus();
  private final Teacher kanjiToHiraganaTeacher_ =
    new KanjiToHiraganaTeacher(this, "田中先生");
  private final Teacher hiraganaToKanjiTeacher_ =
    new HiraganaToKanjiTeacher(this, "本田先生");
  private final Teacher englishToHiraganaTeacher_ =
    new EnglishToHiraganaTeacher(this, "春子先生");
  private final ArrayList<Teacher> teachers_ = new ArrayList<Teacher>(
      Arrays.asList(
          kanjiToHiraganaTeacher_, hiraganaToKanjiTeacher_,
          englishToHiraganaTeacher_));
  private Room room_ = null;
  
  public Syllabus getSyllabus() {
    return syllabus_;
  }
  
  public List<Teacher> teachers() {
    return teachers_;
  }

  public void addSyllabusChangedHandler(
      final SyllabusChangedHandler handler) {
    syllabusChangedHandlers_.add(handler);
  }

  public void removeSyllabusChangedHandler(
      final SyllabusChangedHandler handler) {
    syllabusChangedHandlers_.remove(handler);
  }

  public void synchronise(
      final Syllabus syllabus) {
    syllabus_.synchronise(syllabus);
    for (final SyllabusChangedHandler handler : syllabusChangedHandlers_) {
      handler.onSyllabusChanged(syllabus);
    }
  }

  public void addRoom(
      final Room room) {
    room_  = room;
  }
  
  public Room getRoom() {
    return room_;
  }
}
